/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ru.ssau.utils;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;


public class DatabaseUtil {

    private DatabaseUtil() {

    }

    public static DataSource getDataSource() throws NamingException {
        Context namingContext = new InitialContext();
        DataSource dataSource = (DataSource) namingContext.lookup("jdbc/lab8ds");
        namingContext.close();
        return dataSource;
    }

    public static void closeConnection(Connection connection, Statement statement) {
        try {
            if(statement != null) {
                statement.close();
            }
        } catch (SQLException ex) {
        }
        try {
            if(connection != null) {
                connection.close();
            }
        } catch (SQLException ex) {
        }
    }

    public static String getContainsPattern(String str) {
        return "%"+str+"%";
    }
}
